import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
// 导入全局样式表
import './assets/css/global.css'
import TableTree from 'vue-table-with-tree-grid'

// 导入axios
import axios from 'axios'
// 配置请求的根路径
axios.defaults.baseURL = 'https://www.liulongbin.top:8888/api/private/v1'
//axios请求拦截
axios.interceptors.request.use((config) => {
  // console.log(config);
  // 为请求头对象 添加 token验证 的 Authorization 字段
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config

})
Vue.prototype.$http = axios

Vue.config.productionTip = false

// 注册全局tree组件
Vue.component('tree-table', TableTree)

// 全局过滤器
Vue.filter('dataFormate', function (data) {
  const dt = new Date(data)
  const y = dt.getFullYear();
  const m = Zero(dt.getMonth() + 1);
  const d = Zero(dt.getDate());

  const hh = Zero(dt.getHours());
  const mm = Zero(dt.getMinutes());
  const ss = Zero(dt.getSeconds());

  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})
function Zero(data) {
  return data = data > 9 ? data : '0' + data;
}


new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
